(function(win) {

    var xmlHttp, fn;

    function query(url, callback) {
        fn = callback || function(){};

        xmlHttp = new XMLHttpRequest();

        xmlHttp.open("GET",url, true);
        xmlHttp.send(null);

        xmlHttp.onreadystatechange = onRequest;

    }

    function onRequest () {
        if ( xmlHttp.readyState == 4) {
            if(xmlHttp.status === 200){
                try {
                    fn.call(xmlHttp, JSON.parse(xmlHttp.responseText));
                } catch (e) {
                    console.error(e)
                }

            } else {
                console.log(xmlHttp.status);
            }
        }
    }

    function post(url, data, callback) {
        fn = callback || function(){};

        xmlHttp = new XMLHttpRequest();
        xmlHttp.open("POST", url, true);
        xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

        xmlHttp.send(data);
        xmlHttp.onreadystatechange = onRequest;

    }



    win.getJSON = query;

    win.post = post;

})(window);